<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Home\Model;
use Think\Model;

/**
 * Description of shelve: Shelve record operate.
 *
 * @author Dark
 */
class ShelvedModel extends Model {
    
    /*
     * 增加一条货架记录
     */
    public function addShelveRecord($data) {
        if(!empty($data)) {
            $this->create();
            return $this->add($data);
        } else {
//            Log::write($message,$level=self::ERR,$type='',$destination='',$extra='')
            Log::write('增加货架记录传入空值！');
            return FALSE;
        }
    }
    
    /*
     * 删除一条货架记录
     */
    public function deleteShelveRecordByID($shelveID) {
        if(!empty($shelveID)) {
            $this->create();
            return $this->where('id='.$shelveID)->delete();
        } else {
            Log::write('增加货架记录传入空值！');
            return FALSE;
        }
    }
    
    /*
     * 查询所有的记录
     */
    public function queryAllRecord() {
        return $this->order('shelveTime desc', 'unshelveTime desc')->select();
    }
    
    /*
     * 更新一条记录
     */
    public function updateRecord($ID, $data) {
        if(!empty($ID)) {
            return $this->where('id='.$ID)->save($data);
        } else {
            Log::write('增加货架记录传入空值！');
            return FALSE;
        }
    }
}
